﻿using Microsoft.EntityFrameworkCore;
using Psi.Domain;
//using MySQL.Data.EntityFrameworkCore.Extensions;
//using Pomelo.EntityFrameworkCore.MySql;
//using Pomelo.EntityFrameworkCore.Extensions;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace Psi.Models
{
    public class PsiDbContext : DbContext
    {
        //public void ConfigureServices(IServiceCollection services)
        //{
        //    services.AddControllers();

        //    services.AddDbContext<ApplicationDbContext>(
        //        options => options.UseSqlServer("name=ConnectionStrings:DefaultConnection"));
        //}

        public PsiDbContext(DbContextOptions<PsiDbContext> options) : base(options)
        {
        }

        protected override void OnModelCreating(ModelBuilder builder)
        {
            base.OnModelCreating(builder);
            //注册映射配置
            builder.ApplyConfigurationsFromAssembly(this.GetType().Assembly);
        }

        public DbSet<User> Users { get; set; }
        public DbSet<Catelog> Catelogs { get; set; }


        //public PomeloMySqlDbContext(DbContextOptions<PomeloMySqlDbContext> options)
        //    : base(options)
        //{ }
        ////public DbSet<Article> Articles { get; set; }
        ////public DbSet<Banner> Banners { get; set; }
        ////public DbSet<Category> Categorys { get; set; }
        ////public DbSet<Goods> Goods { get; set; }

        //public DbSet<User> Users { get; set; }

        ////protected override void OnConfiguring(DbContextOptionsBuilder optoionsBuilder)
        ////{
        ////    var sqliteConnectionInitializer = new SqliteCreateDatabaseIfNotExists<MySqlDbContext>(modelBuilder);
        ////    Database.SetInitializer(sqliteConnectionInitializer);
        ////    //映射到数据库中的表 !!!!!!
        ////    //modelBuilder.Entity<User>().ToTable("User");
        ////}
    }
    //public static class ContextFactory
    //{
    //    public static MySqlDbContext Create(string connectionString)
    //    {
    //        var optionsBuilder = new DbContextOptionsBuilder<MySqlDbContext>();
    //        optionsBuilder.UseMySQL(connectionString);

    //        //Ensure database creation
    //        var context = new MySqlDbContext(optionsBuilder.Options);
    //        context.Database.EnsureCreated();

    //        return context;
    //    }
    //}
}